class Player:
# Algorithm: Hunt with other hunters (collaborators), slack with other slackers.
# Calculate the minimum collaborator reputation based on who we've previously
# hunted with, and then hunt with anyone above that reputation.

	def __init__(self):
		# Data from previous round, helps decide when to hunt next
		self.last_player_reputations = None
		self.last_decisions = None
		self.last_food_earnings = None
		self.last_reputation = 1.0
		self.last_min_collaborator_rep = 1.0
		
		# Used to calculate a collaborator's minimum rep
		self.collaborator_hunts = 0
		self.collaborator_slacks = 0

		# Used to see if we're outcast
		self.ditched_by_tribe = False
		self.total_collaborators = 0
		
	def hunt_choices(self, round_number, current_food, current_reputation, m, player_reputations):
		num_players = len(player_reputations) # Not including us
		hunt_decisions = []

		if num_players <= 1 or self.ditched_by_tribe is True:
			# No one left to collaborate, or we've been ditched
			hunt_decisions = ['s' for x in player_reputations]
		elif round_number <= 1:
			# First round, assume all collaborators hunt
			hunt_decisions = ['h' for x in player_reputations]
			self.collaborator_hunts = len(player_reputations)
			self.total_collaborators = len(player_reputations)
		else:
			# Check our results from last round and recalibrate
			hunters_who_ditched_us = 0
			for i in range(len(self.last_food_earnings)):
				their_reputation = self.last_player_reputations[i]
				my_decision = self.last_decisions[i]
				food_earning = self.last_food_earnings[i]
				if my_decision == 'h' and food_earning == -3 and their_reputation >= self.last_reputation:
					# A player with >= rep ditched us on the hunt, that's bad
					hunters_who_ditched_us += 1
				if my_decision == 's' and food_earning == 1 and their_reputation >= self.last_min_collaborator_rep * 0.90:
					# I ditched a hunter with 90% expected rep, 
					# recalibrate in case they're trying to collaborate
					self.collaborator_hunts -= 1
					self.collaborator_slacks += 1
			if hunters_who_ditched_us >= self.total_collaborators:
				# Everyone we tried to hunt with ditched us, we're done
				self.ditched_by_tribe = True

			# Expected minimum collaborator reputation for this round
			min_collaborator_rep = self.collaborator_hunts / float(self.collaborator_hunts + self.collaborator_slacks)

			# Make hunt decisions for this round based on new minimum reputation
			self.total_collaborators = 0
			for p in player_reputations:
				if p >= min_collaborator_rep and self.ditched_by_tribe is False:
					hunt_decisions.append('h')
					self.collaborator_hunts += 1
					self.total_collaborators += 1
				else:
					hunt_decisions.append('s')
					self.collaborator_slacks += 1
		
			# Save data for next round
			self.last_min_collaborator_rep = min_collaborator_rep
			
		# Save data for next round
		self.last_player_reputations = player_reputations
		self.last_decisions = hunt_decisions
		self.last_reputation = current_reputation
		
		return hunt_decisions

	def hunt_outcomes(self, food_earnings):
		self.last_food_earnings = food_earnings

	def round_end(self, award, m, number_hunters):
		pass
